<?php

namespace app\hannel\command;

use qcloudsms\SmsMultiSender;
use qcloudsms\SmsSingleSender;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class Wanqing extends Command
{
    protected function configure()
    {
        $this->setName('wanqing')->setDescription('Command Test');
    }

    protected function execute(Input $input, Output $output)
    {
        $tztime = strtotime('-3 day',strtotime(date('Y-m-d')));

        $times = [];
        for($i = 5;$i<=30;$i+=5) {
            $times[] = date('Y-m-d',strtotime("+{$i} day"));
        }

        $virtual_address = db('wanqing_virtual_address')
            ->alias('virtual_address')
            ->join('__USER__ user','virtual_address.uid = user.id')
            ->where([
                'FROM_UNIXTIME(end_time,\'%Y-%m-%d\')' => ['in',$times]
            ])
            ->field('virtual_address.id,user.mobile,FROM_UNIXTIME(end_time,\'%Y-%m-%d\') endtime,group_concat(virtual_address.id) ids')
            ->group('uid,endtime')
            ->order('uid,endtime')
            ->select();

        $time = strtotime(date('Y-m-d'));
        foreach ($virtual_address as $val) {
            $day = (strtotime($val['endtime']) - $time) / 86400;
            $this->sendsms($val['mobile'], 138424,[$val['ids'],$day]);
        }
    }

    /**
     * 发送短信
     * @param $phone_list
     * @param $templid
     */
    private function sendsms($phone_list, $templid,$params_list)
    {
        $multiSender = new SmsSingleSender('1400047725', 'd9c93046f4f45a7f591914ca5b506923');
        $result = $multiSender->sendWithParam("86", $phone_list, $templid, $params_list, "", "", "");
    }
}